﻿namespace ClassyBlog.DataAccess.Specs.Unit
{
    using Machine.Specifications;
    using NSubstitute;

    using DomainObjects;
    using Infrastructure;

    public abstract class PageFactorySpec
    {
        protected const string DataPath =
            @"c:\inetpub\wwwroot\classyblog\app_data\pages";

        protected const string FileName = "2010-04-02-17-30-00_about-us.md";

        protected static IFileSystem fileSystem;
        protected static PageFactory factory;

        protected static Page page;

        Establish context = () =>
        {
            fileSystem = Substitute.For<IFileSystem>();
            factory = new PageFactory(fileSystem);
        };
    }

    [Subject(typeof(PageFactory))]
    public class when_page_is_created : PageFactorySpec
    {
        Establish context = () =>
            fileSystem.FileExists(Arg.Any<string>()).Returns(true);

        Because of = () =>
            page = factory.Create(DataPath, DataPath + "/" + FileName);

        It should_return_lazy_page = () => page.ShouldBeOfType<LazyPage>();
    }
}